package com.ly.lypopupwindowdemo.activity;

import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.ly.lypopupwindowdemo.R;
import com.ly.lypopupwindowdemo.views.HorizontalProgressView;

/**
 * 来自于：
 * http://www.jianshu.com/p/7ecdb565e8f0
 * http://www.jianshu.com/p/7ecdb565e8f0
 * http://www.jianshu.com/p/7ecdb565e8f0
 */
public class CustomProgressbarActivity extends AppCompatActivity {


    ProgressBar progressBar,progressBar2;
    TextView text,text2;

    HorizontalProgressView  customProgress;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_custom_progressbar);

        progressBar = (ProgressBar) findViewById(R.id.progress);
        text = (TextView) findViewById(R.id.text);

        progressBar2 = (ProgressBar) findViewById(R.id.progress2);
        text2 = (TextView) findViewById(R.id.text2);

        customProgress = (HorizontalProgressView) findViewById(R.id.custom_progress);

        customProgress.setProgress(50);

        new Thread(new Runnable() {
            @Override
            public void run() {
                int i =1;
                while (i<100){
                    i++;
                    try {
                        Thread.sleep(80);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }

                    final int j=i;
                    progressBar.setProgress(i);
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            text.setText(j+"%");
                        }
                    });

                }
            }
        }).start();





        new Thread(new Runnable() {
            @Override
            public void run() {
                int i =1;
                while (i<100){
                    i++;
                    try {
                        Thread.sleep(80);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }

                    final int j=i;
                    progressBar2.setProgress(i);
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            text2.setText(j+"%");
                        }
                    });

                }
            }
        }).start();

    }
}
